
<?php

require_once 'Connection.php';
require_once 'Functions.php';


$func = new Functions();
$con = new Connection();
$conn = $con->configDB();

date("d-m-Y");
$dateStart = new DateTime(date('26-08-2014'));
$dateEnd = new DateTime(date('28-08-2014'));

$playerID_Arr = [66, 67, 69, 70, 71, 71, 74, 75, 77, 78];

while ($dateStart < $dateEnd) {

    for ($i = 0; $i < rand(50, 150); $i++) {
        $PlayerID = $playerID_Arr[rand(0, count($playerID_Arr) - 1)];
        $BetDate = (string) $dateStart->format('d-m-Y');
        $BetTime = "13:40";
        $BetNumber = $func->numToString(rand(0, 99), 2);
        $BetMoney = rand(50, 1500) * 1000;
        $WinTime = 0;
        $Pending = 0;

        $dayInWeek = $func->getDayInWeekNumber((string) $dateStart->format('D'));
        $provinceAndSubThreadRule_Arr = getProvinceAndSubThreadRuleByDayInWeek($conn, $dayInWeek);

        $rd = rand(0, count($provinceAndSubThreadRule_Arr) - 1);
        $SubThreadRuleID = "BL2S" . $provinceAndSubThreadRule_Arr[$rd]["RegionID"];
        $ProvinceID = $provinceAndSubThreadRule_Arr[$rd]["ProvinceID"];

        //insertBetThread($conn, $PlayerID, $SubThreadRuleID, $BetDate, $BetTime, $BetNumber, $BetMoney, $WinTime, $Pending, $ProvinceID);
    }

    $dateStart->add(new DateInterval('P1D'));
}

function getProvinceAndSubThreadRuleByDayInWeek($conn, $dayInWeek) {
    $strQuery = mysqli_query($conn, "SELECT pd.ProvinceID, (SELECT p.RegionID FROM provinces as p WHERE p.ProvinceID = pd.ProvinceID) as RegionID FROM province_day as pd WHERE pd.DayID = $dayInWeek");
    $arr = array();
    while ($row = mysqli_fetch_array($strQuery)) {
        array_push($arr, $row);
    }
    return $arr;
}

function insertBetThread($conn, $PlayerID, $SubThreadRuleID, $BetDate, $BetTime, $BetNumber, $BetMoney, $WinTime, $Pending, $ProvinceID) {
    mysqli_query($conn, "INSERT INTO betthreads VALUES (NULL, $PlayerID, '$SubThreadRuleID', '$BetDate', '$BetTime', '$BetNumber', $BetMoney, $WinTime,$Pending,'$ProvinceID')");
}
